package com.cby.jetpack.sample.binding

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.cby.jetpack.sample.R
import com.cby.jetpack.sample.binding.adapter.TestListAdapter
import com.cby.jetpack.sample.binding.data.Example
import com.cby.jetpack.sample.databinding.ActivityDataBindListBinding
import com.cby.jetpack.sample.ext.dataBinding

/**
 * @description: TestDataBindingListActivity
 *
 * @author ChenBaoyang
 * @date 8/9/21 17:51
 */
class TestDataBindingListActivity : AppCompatActivity() {

    private val binding: ActivityDataBindListBinding by dataBinding(R.layout.activity_data_bind_list)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val adapter = TestListAdapter()
        binding.recyclerView.layoutManager = LinearLayoutManager(this@TestDataBindingListActivity)
        binding.recyclerView.setHasFixedSize(true)
        binding.recyclerView.adapter = adapter
        adapter.addData(testData())
    }


    private fun testData(): MutableList<Example> {
        val list: MutableList<Example> = mutableListOf()

        for (i in 0..10) {
            list.add(Example("Example - $i"))
        }

        return list
    }
}